env:
  global:
    - RUSTFLAGS="-D warnings"
matrix:
  fast_finish: true
  include:
    # CI targets
    - os: osx
      rust: stable
      env: TARGET=x86_64-apple-darwin
    - os: linux
      dist: trusty
      rust: stable
      env:
        - TARGET=x86_64-unknown-linux-gnu
        - COMPILER_NAME=gcc
        - CXX=g++-5
        - CC=gcc-5
    # rustdoc
    - os: linux
      dist: trusty
      rust: stable
      env:
        - TARGET=x86_64-unknown-linux-gnu
        - COMPILER_NAME=gcc
        - CXX=g++-5
        - CC=gcc-5
        - PACKAGE=doc
        - secure: "J9YvYryNyAZZSfJfXw64xHGmuwbwjPWxfvQ1vaLoC3ZXla2Nf1tEQN7P0UgnJkC3MZYop/yIZFa0bbdTG0Kef7+RHeD15Yp70bI6fyP9i048KRQYLPubTOHWIm5Ow6qIMo5hKZsVO3z+Lg7s3/y6L+DR5bT3PXWdZHovhe1QlA8="
    # nightly builds
    - os: linux
      dist: trusty
      rust: stable
      env:
        - TARGET=x86_64-unknown-linux-gnu
        - COMPILER_NAME=gcc
        - CXX=g++-5
        - CC=gcc-5
        - PACKAGE=ubuntu
        - secure: "HwY2nRi7xuAQTkuVWgUupdVcJmutiiq+A4iDCbC4NI/vRB7WKCifxlzivCeTJMBu22LSLPJBMoaQ0S7w1PLaPkuG2d0qqFhublmhzk5sLaQt6AiwpEnJaHLqGy6aDVPDbqd4EWlPZ1MMCV+uXhtHzsg9XmrlZH9l5hMGx3mUDJw="
      branches:
        only:
          - master
    - os: linux
      dist: trusty
      rust: stable
      env:
        - TARGET=x86_64-unknown-linux-gnu
        - PACKAGE=debian
        - secure: "HwY2nRi7xuAQTkuVWgUupdVcJmutiiq+A4iDCbC4NI/vRB7WKCifxlzivCeTJMBu22LSLPJBMoaQ0S7w1PLaPkuG2d0qqFhublmhzk5sLaQt6AiwpEnJaHLqGy6aDVPDbqd4EWlPZ1MMCV+uXhtHzsg9XmrlZH9l5hMGx3mUDJw="
      branches:
        only:
          - master
    - os: linux
      dist: trusty
      rust: stable
      env:
        - TARGET=x86_64-unknown-linux-gnu
        - PACKAGE=fedora
        - secure: "HwY2nRi7xuAQTkuVWgUupdVcJmutiiq+A4iDCbC4NI/vRB7WKCifxlzivCeTJMBu22LSLPJBMoaQ0S7w1PLaPkuG2d0qqFhublmhzk5sLaQt6AiwpEnJaHLqGy6aDVPDbqd4EWlPZ1MMCV+uXhtHzsg9XmrlZH9l5hMGx3mUDJw="
      branches:
        only:
          - master
    - os: osx
      rust: stable
      env:
        - TARGET=x86_64-apple-darwin
        - PACKAGE=osx
        - secure: "HwY2nRi7xuAQTkuVWgUupdVcJmutiiq+A4iDCbC4NI/vRB7WKCifxlzivCeTJMBu22LSLPJBMoaQ0S7w1PLaPkuG2d0qqFhublmhzk5sLaQt6AiwpEnJaHLqGy6aDVPDbqd4EWlPZ1MMCV+uXhtHzsg9XmrlZH9l5hMGx3mUDJw="
      branches:
        only:
          - master

sudo: false
services:
  - docker
notifications:
  webhooks:
    urls:
      - "https://webhooks.gitter.im/e/b55d667112f600c858d4"
  irc:
    channels:
      - "chat.freenode.net#panopticon"
    on_success: change
    on_failure: always
language: rust
cache: cargo
addons:
  apt:
    sources: &sources
      - ubuntu-toolchain-r-test
    packages:
      # qml-rust
      - g++-5
      # panopticon
      - cmake
      - qt5-default
      - qtdeclarative5-dev
      - libqt5qml-quickcontrols
      - qtbase5-private-dev
      - libqt5svg5-dev
      - pkg-config
      - git
      - build-essential
      # kcov
      - libelf-dev
      - libcurl4-openssl-dev
      - libdw-dev
before_install: |
   if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
      brew update
      brew install qt
      brew link qt --force
      brew linkapps qt
      export HOMEBREW_QT5_VERSION=$(brew list --versions qt | rev | cut -d ' ' -f1 | rev)
      ln -s /usr/local/Cellar/qt/$HOMEBREW_QT5_VERSION/mkspecs /usr/local/mkspecs
      ln -s /usr/local/Cellar/qt/$HOMEBREW_QT5_VERSION/plugins /usr/local/plugins
   fi
before_script: |
   if [[ "$TRAVIS_OS_NAME" == "linux" && "$PACKAGE" == "" ]]; then
      (cargo install cargo-travis || true)
      export PATH=$HOME/.cargo/bin:$PATH
   fi
script: |
  if [[ "$PACKAGE" != "" && ( "$TRAVIS_BRANCH" != "master" || "$TRAVIS_PULL_REQUEST" != "false" ) ]]
  then
    echo ""
  else
    if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export QTDIR64=/usr/local; fi &&
    case "$PACKAGE" in
    "osx")
      cd pkg/osx/ &&
      ./package_dmg.sh &&
      curl -vT Panopticon.dmg -u upload:$FTP_PASSWD -Q "-SITE CHMOD 664 panopticon-master.dmg" ftp://files.panopticon.re/panopticon-master.dmg
      ;;
    "ubuntu")
      cd pkg/debian &&
      docker build -t panopticon-build -f Dockerfile.ubuntu . &&
      docker run -v `pwd`:/out panopticon-build &&
      curl -vT panopticon_0.16_amd64.deb -u upload:$FTP_PASSWD -Q "-SITE CHMOD 664 panopticon-master-xenial.deb" ftp://files.panopticon.re/panopticon-master-xenial.deb
      ;;
    "doc")
      cargo doc --all &&
      cd target/doc &&
      tar cvf ../../doc.tar * &&
      curl -H "X-Token: $DOC_TOKEN" --data-binary @../../doc.tar https://doc.panopticon.re/update
      ;;
    "debian")
      cd pkg/debian &&
      docker build -t panopticon-build -f Dockerfile.debian . &&
      docker run -v `pwd`:/out panopticon-build &&
      curl -vT panopticon_0.16_amd64.deb -u upload:$FTP_PASSWD -Q "-SITE CHMOD 664 panopticon-master-stretch.deb" ftp://files.panopticon.re/panopticon-master-stretch.deb
      ;;
    "fedora")
      cd pkg/fedora &&
      docker build -t panopticon-build . &&
      docker run -v `pwd`:/out panopticon-build &&
      curl -vT panopticon_0.16_amd64.rpm -u upload:$FTP_PASSWD -Q "-SITE CHMOD 664 panopticon-master-fedora-25.rpm" ftp://files.panopticon.re/panopticon-master-fedora-25.rpm
      ;;
    "")
      cargo build --verbose --all &&
      cargo test --verbose --all
      ;;
    *)
      exit
      ;;
    esac
  fi
after_success: |
  # send coverage report to coveralls.io
  if [[ "$TRAVIS_OS_NAME" == "linux" && "$PACKAGE" == "" ]]; then
    cargo coveralls --verbose --all
  fi
